﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace StuffNET.Math
{
    public class Geometry
    {
        /// <summary>
        /// Calculates the distance between two coordinates
        /// </summary>
        /// <param name="c1">The first coordinate</param>
        /// <param name="c2">The second coordinate</param>
        /// <returns>The distance</returns>
        public static double GetDistance(Coordinate c1, Coordinate c2)
        {
            return GetDistance(c1.X, c1.Y, c2.X, c2.Y);
        }
        
        /// <summary>
        /// Calculates the distance between two coordinates
        /// </summary>
        /// <param name="x1">The x value of the first coordinate</param>
        /// <param name="y1">The y value of the first coordinate</param>
        /// <param name="x2">The x value of the second coordinate</param>
        /// <param name="y2">The y value of the second coordinate</param>
        /// <returns>The distance</returns>
        public static double GetDistance(int x1, int y1, int x2, int y2)
        {
            return GetDistance(x1 * 1.0, y1, x2, y2);
        }

        /// <summary>
        /// Calculates the distance between two coordinates
        /// </summary>
        /// <param name="x1">The x value of the first coordinate</param>
        /// <param name="y1">The y value of the first coordinate</param>
        /// <param name="x2">The x value of the second coordinate</param>
        /// <param name="y2">The y value of the second coordinate</param>
        /// <returns>The distance</returns>
        public static double GetDistance(double x1, double y1, double x2, double y2)
        {
            return System.Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
        }

        /// <summary>
        /// Calulates the angle between two coordinates
        /// </summary>
        /// <param name="c1">The first coordinate</param>
        /// <param name="c2">The second coordniate</param>
        /// <returns>The angle (in radian)</returns>
        public static double GetAngle(Coordinate c1, Coordinate c2)
        {
            return GetAngle(c1.X, c1.Y, c2.X, c2.Y);
        }

        /// <summary>
        /// Calculates the angle between two coordinates
        /// </summary>
        /// <param name="x1">The x value of the first coordinate</param>
        /// <param name="y1">The y value of the first coordinate</param>
        /// <param name="x2">The x value of the second coordinate</param>
        /// <param name="y2">The y value of the second coordinate</param>
        /// <returns>The angle (in radian)</returns>
        public static double GetAngle(int x1, int y1, int x2, int y2)
        {
            return GetAngle(x1 * 1.0, y1, x2, y2);
        }

        /// <summary>
        /// Calculates the angle between two coordinates
        /// </summary>
        /// <param name="x1">The x value of the first coordinate</param>
        /// <param name="y1">The y value of the first coordinate</param>
        /// <param name="x2">The x value of the second coordinate</param>
        /// <param name="y2">The y value of the second coordinate</param>
        /// <returns>The angle (in radian)</returns>
        public static double GetAngle(double x1, double y1, double x2, double y2)
        {
            return System.Math.Atan2(y2 - y1, x2 - x1);
        }

    }
}
